Assignment Statements
Assignment statements set the value of a variable or like identifier in a script. Assignment statements use the assignment operator (:=) to set the value of the identifier on the left-hand side of the symbol to the value of the constant or identifier on the right-hand side of the symbol. This may also be thought of as assigning the value of the identifier on the right-hand side to the identifier on the left.
The generalized syntax for assignment statements is:
<identifier> := <identifier or constant value>;
The identifier on the left-hand side may be any VectorScript data type; it may also be an array element, a full array reference, or a structure field.
For example:
 
POINT = STRUCTURE
s : STRING;
i : INTEGER;
h : HANDLE;
textdata : ARRAY[1..100] OF STRING;
p1,p2 : POINT;
{ assignment of constant value to a variable }
{ assignment of return value to variable }
{ assignment of return value to variable }
{ assignment of variable value to array element }
{ assignment of values to structure members }
{ assignment of member value to another member }
{ assignment of member value to another member }
From the example, it is evident that the assignment statement is very flexible. The example makes use of constants, variables, structure fields, and function return values when assigning values to an identifier. Note also that more than one statement can reside on a single line, as long as they are separated by a semi-colon indicating the end of each statement.
While assignment statements are very flexible in how they get or assign values, they do observe some rules regarding compatibility of data types. When writing assignment statements, the following rules should be observed:
*
A variable of REAL type may be set to a REAL, INTEGER, or LONGINT value, as well as any expression yielding those results.
*
A LONGINT variable may be set to a LONGINT or INTEGER value or any expression yielding such a value. It may also be set to a REAL value, but the value will be truncated and rounded to the nearest whole value.
*
An INTEGER variable may be set to an INTEGER value, or any expression yielding such a value. It may also be set to a REAL value, but the value will be truncated and rounded to the nearest whole value.
*
A BOOLEAN variable may be set a BOOLEAN value or an expression yielding such a value.
*
A STRING variable may be set to a STRING or CHAR value or any expression yielding those values. It may also be set to an ARRAY or DYNARRAY OF CHAR value; however, the value in the array will be truncated to 255 characters.
*
A CHAR variable may be set to a CHAR value or any expression yielding a CHAR value. It may also be set to a STRING value, but will be truncated if the STRING is greater than 1 character in length.
*
A HANDLE variable may be set to a HANDLE value or any expression yielding a HANDLE value.
Assignment statements also support block copying of values in arrays when they are used without an array element index in a script. This method facilitates transferring large amounts of data without the need for copying on an element-by-element basis. For example:
 
In order to transfer the values in values1 to values2, it would appear that multiple assignment statements are needed, one for each array element. For large arrays, this would be a time-consuming task. Fortunately, VectorScript overloads (extends the functionality of) the assignment operator so that operation to copy the values becomes a single statement:
 
The assignment statement copies the data from the values1 array directly into the corresponding elements of the values2 array. This sort of assignment operation can be also be performed with dynamic arrays; in both cases, however, the dimensions of the arrays on both sides of the assignment operator must be exactly the same in order to complete the operation.
Vectors and structures may also be copied in this manner; the member values of the item on the right side of the assignment operator will be copied into the corresponding member fields of the item on the left side of the operator. For example, the values in a vector direction_vector1 could be copied into another vector:
new_vector:= direction_vector1;
The values in the fields of direction_vector1 would be copied into the fields of new_vector without the need for assignment statements for each field.

Statements : Assignment Statements

Nemetschek NA
Phone: 410.290.5114
Fax: 410.290.8050